package com.example.a2302fx.login

import androidx.lifecycle.viewModelScope
import com.example.base.entity.LoginEntity
import com.example.base.mvvm.BaseViewModel
import com.example.base.mvvm.Res
import com.example.base.net.SingleLiveData
import kotlinx.coroutines.launch

class LoginViewModel:BaseViewModel() {
    val loginSuccess = SingleLiveData<Res<LoginEntity>>()
    val loginFail = SingleLiveData<String>()
    fun login(account:String,password:String){
        viewModelScope.launch {
            try {
                val map = mutableMapOf<String,Any>()
                map["account"] = account
                map["password"] = password
                loginSuccess.postValue(apiService.login(mapToBody(map)))
            }catch (e:Exception){
                loginFail.postValue(e.message.toString())
            }
        }
    }

}